package com.woniu.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.woniu.entity.BillList;
import com.woniu.entity.FinalTrialExportVO;
import com.woniu.entity.KeyWords;
import com.woniu.entity.UsualExportVO;
import com.woniu.service.BillManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @description: 账单列表
 * @author: sunkun
 * @date: 2022/9/29 11:16
 * @version 1.0
 */
@Api(value = "账单管理接口", tags = {"账单列表"})
@RestController
@RequestMapping("bill")
public class BillManagerController extends BaseController {
    @Autowired
    BillManagerService billManagerService;

    @ApiOperation(value = "查询所有的订单列表", response= BillList.class,  httpMethod="GET", tags = {"账单列表"})
    @ApiImplicitParam(name = "billList",value = "账单实体",required = true)
    @GetMapping("/billList")
    public TableDataInfo findBillList(BillList billList){
        startPage();
        List<BillList> all = billManagerService.findAllBill(billList);
        return getDataTable(all);
    }

    @ApiOperation(value = "添加客户备注", response= BillList.class, produces="application/json", httpMethod="PUT", tags = {"账单列表"})
    @PutMapping("/remark")
    public AjaxResult clientRemark(@RequestBody BillList billList){
        if(billManagerService.addClientRemark(billList)){
            return AjaxResult.success("备注添加成功！");
        }
        return AjaxResult.error("备注添加失败！");
    }

    @PostMapping("/exportXlsx")
    @ResponseBody
    public void export(HttpServletResponse response, BillList data){
        System.out.println(data);
        List<BillList> allBill = billManagerService.findAllBill(data);
        ExcelUtil<BillList> billListExcelUtil = new ExcelUtil<>(BillList.class);
        billListExcelUtil.exportExcel(response,allBill,KeyWords.EXPORT_FINAL_TRIAL_NAME);
    }
}
